package com.example.menutest;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    TextView text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text =(TextView) findViewById(R.id.textView);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu,menu);
        return super.onCreateOptionsMenu(menu);
    }
    @SuppressLint("NonConstantResourceId")
    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        int itemId=item.getItemId();
        switch (item.getItemId()){
            case R.id.size1:
                text.setTextSize(10 * 2);
                break;
            case R.id.size2:
                text.setTextSize(16 * 2);
                break;
            case R.id.size3:
                text.setTextSize(20 * 2);
                break;
            case R.id.commonmenu:
                Toast.makeText(MainActivity.this,"你点击了普通菜单项",Toast.LENGTH_SHORT)
                        .show();
                break;
            case R.id.color1:
                text.setTextColor(Color.RED);
                break;
            case R.id.color2:
                text.setTextColor(Color.BLACK);
                break;



        }
        return super.onOptionsItemSelected(item);
    }
}